
public class Interaction
{
	private double time;
	
	public Interaction(BillardBall state1,BillardBall state2)
	{
		double a = Math.pow(state2.getVelocity().substract(state1.getVelocity()).getLength(), 2);
		double b = state2.getPosition().substract(state1.getPosition()).dotProduct(state2.getVelocity().substract(state1.getVelocity()));
		double c = Math.pow(state2.getPosition().substract(state1.getPosition()).getLength(),2)-Math.pow(2*state2.getRadius(), 2);
		
		if(b>0 || b*b-a*c < 0)
		{
			time = Double.POSITIVE_INFINITY;
		}
		else
		{
			time = (-b-Math.sqrt(b*b-a*c))/a;
		}
	}
	
	public double getTime()
	{
		return time;
	}
}
